//          获取路线信息

var busflag; //实时获取公交定时器
function busSearch(a, cityname) {
	var busName = $("#line_input").val();
	//正则保证只搜索数字
	//	var patt1 = /[0-9]+/;
	//	busName = busName.match(patt1)[0];
	var upDown = a ? a : 0;
	if(busName != "") {
		$.ajax({
			type: 'post',
			url: allUrl,
			async: false,
			cache: false,
			data: {
				type: "bus_line_query_info",
				LINECODE: busName,
				UPDOWN: upDown,
				AREA: cityname
			},
			jsonp: "callbackparam",
			//服务端用于接收callback调用的function名的参数
			jsonpCallback: "data",
			dataType: 'jsonp',
			beforeSend: function() {
				$("#r-result").html("");
				loading($("#r-result"));
			},
			success: function(data) {
				map.clearOverlays();
				$('#fachetime').popover('hide');
				if(data.CODE == "1") {
					if(isEncrypt(data.DATA, data.MDATA)) {
						clearTimeout(busflag)
						$("#refreshMap_gj").show();
						$("#ttt").show();
						var d = data.DATA;
						d = JSON.parse(d);
						$("#r-result").html("");
						d.IS_MONTHLY_TICKET = d.IS_MONTHLY_TICKET == "0" ? "月票无效" : "月票有效";
						d.IS_SELF_TICKETING = d.IS_SELF_TICKETING == "0" ? "有人售票" : "无人售票";
						var tag = '';
						var busInfo = d.stationInfoArray;
						var busPathInfo = d.coordinateArray;
						var newPathArray = [];
						var fctime = d.DEPARTURE_TIME;
						tag += '<p class="f16">' + d.LINENAME + '：<span>' + yzStationStr(busInfo[0].STATIONNAME) + '</span>→<span>' + yzStationStr(busInfo[busInfo.length - 1].STATIONNAME) + '</span></p>' +
							'<p class="bb">线路里程：' + d.LINELENGTH + '  公里</p>' +
							'<p class="busInfo"><span>全程票价：' + d.NORMALWHOLETRIPFARE + '元</span><span><a id="fachetime" href="javascript:;" type="button" class="btn " title="发车时间" data-container="body" data-toggle="popover" data-content=' + fctime + '>发车时间</a></span></p>' +
							'<p class="busInfo bb"><span>' + d.IS_SELF_TICKETING + '</span><span>' + d.IS_MONTHLY_TICKET + '</span></p>' +
							'<p class="f16">沿途公交站点：</p>'
						var opts = {
							width: 200, // 信息窗口宽度
						}
						var blength = busInfo.length;
						for(var i = 0; i < blength; i++) {
							busInfo[i].STATIONNAME = yzStationStr(busInfo[i].STATIONNAME);
							var content = "<p class='cb fb f16 mb10' style='text-align:center;'>" + busInfo[i].STATIONNAME + "</p>" +
								"<p class='mb10' style='text-align:center;'>" + busInfo[i].ROADNAMEOFSTATIONLOCATED + "</p>"; //站点具体地址;
							var daozhequ = busInfo[i].LONGITUDELOCATIONOFSTATION + "," + busInfo[i].LATITUDELOCATIONOFSTATION;
							//跳转出行规划
							content += '<div class=" tzdcx" style="text-align: center;" >' +
								'<a href="javascript:;" ><button onclick="tzdcxgh(this);" name="' + daozhequ + '" style="outline-style: none;letter-spacing: 2px;width: 80px" type="button" class="btn btn-warning" >到这去</button></a>' +
								'</div>'
							tag += '<p class="gj_p_style" onclick="getInfo(this)" data-address="' + busInfo[i].ROADNAMEOFSTATIONLOCATED + '" data-name="' + busInfo[i].STATIONNAME + '" data-w="' + busInfo[i].LONGITUDELOCATIONOFSTATION + '" data-j="' + busInfo[i].LATITUDELOCATIONOFSTATION + '">' + (i + 1) + '.' + busInfo[i].STATIONNAME + '</p>'
							//创建公交站点
							var point1 = new BMap.Point("" + busInfo[i].LONGITUDELOCATIONOFSTATION + "", "" + busInfo[i].LATITUDELOCATIONOFSTATION + "");
							//创建图标
							var taxiIcon;
							taxiIcon = new BMap.Icon("img/bus/pic_zhandianyuan.png", new BMap.Size(14, 14));
							//										}
							var marker1 = new BMap.Marker(point1, {
								icon: taxiIcon
							}); // 创建标注
							map.addOverlay(marker1);

							addClickHandler(content, marker1);
						}

						function addClickHandler(content, marker) {
							marker.addEventListener("click", function(e) {
								openInfo(content, e)
							})
						}

						function openInfo(content, e) {
							var p = e.target;
							var point = new BMap.Point(p.getPosition().lng, p.getPosition().lat);
							var infoWindow = new BMap.InfoWindow(content, opts); // 创建信息窗口对象
							map.openInfoWindow(infoWindow, point); //开启信息窗口
						}
						$("#r-result").append(tag);
						for(var s = 0; s < busPathInfo.length; s++) {
							var c = busPathInfo[s];
							var a = Number(c.LAITITUDE);
							var b = Number(c.LONGITUDE);
							newPathArray.push(new BMap.Point(b, a))
						}
						//创建折线	
						var sy = new BMap.Symbol(BMap_Symbol_SHAPE_BACKWARD_OPEN_ARROW, {
							scale: 0.6, //图标缩放大小
							strokeColor: '#fff', //设置矢量图标的线填充颜色
							strokeWeight: '2', //设置线宽
						});
						//						var icons = new BMap.IconSequence(sy, '10', '30');
						var polyline = new BMap.Polyline(newPathArray, {
							enableEditing: false, //是否启用线编辑，默认为false
							enableClicking: true, //是否响应点击事件，默认为true
							//							icons: [icons],
							strokeWeight: '8', //折线的宽度，以像素为单位
							strokeOpacity: 0.8, //折线的透明度，取值范围0 - 1
							strokeColor: "#18a45b" //折线颜色
						});
						map.addOverlay(polyline);
						//创建起终点
						//										var beginMarkX = d.coordinateArray[0].LONGITUDE;
						//										var beginMarkY = d.coordinateArray[1].LAITITUDE;
						//										var endMarkX = d.coordinateArray[d.coordinateArray.length - 1].LONGITUDE;
						//										var endMarkY = d.coordinateArray[d.coordinateArray.length - 1].LAITITUDE;
						//										var beginmark = new BMap.Marker(new BMap.Point(beginMarkX, beginMarkY), {
						//											icon: new BMap.Icon("../../img/public/Pic_zd.png", new BMap.Size(30, 30))
						//										})
						//										var endmark = new BMap.Marker(new BMap.Point(endMarkX, endMarkY), {
						//											icon: new BMap.Icon("../../img/public/Pic_qd.png", new BMap.Size(30, 30))
						//										})
						//										map.addOverlay(beginmark)
						//										map.addOverlay(endmark)
						//创建公交实时位置

						bustimeout = false;
						getPmapBus(busName, upDown);
						//						time1(busName, upDown);

						//让线路试应屏幕
						map.setViewport(newPathArray)
					} else {
						alert(alertInfo)
					}
				} else {
					$("#r-result").html("<p style='text-align: center;'>请按提示输入正确线路</p>")
				}
				$("#fachetime").popover({
					html: false
				});

			}
		});
	}

}